<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>西瓜后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/purchasing_management.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form">
                <div class="step_block">
                    <h4> 请选择车辆确认该批采购单</h4>
                    <table id="orderTable">
                        <thead>
                        <tr>
                            <th><input type="checkbox" name="orderAll"  lay-skin="primary" class="layui-input" lay-filter="purchaseCheckboxAll"/></th>
                            <th>品牌</th>
                            <th>车系</th>
                            <th>车型</th>
                            <th>外观/内饰颜色</th>
                            <th>车架号</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <input type="hidden" name="yes" value=""/>
                            <td><input type="checkbox" name="order"  lay-skin="primary" class="layui-input" lay-filter="purchaseCheckbox"/></td>
                            <td>大众</td>
                            <td>朗逸</td>
                            <td>2018款自动精英型</td>
                            <td>黑/棕</td>
                            <td><span class="VIN">LS5ADE0AB046793</span></td>
                        </tr>
                        <tr>
                            <td><input type="checkbox" name="order"  lay-skin="primary" class="layui-input"/><span class="layui-text-gray" color999>不可选</span></td>
                            <td>大众</td>
                            <td>朗逸</td>
                            <td>2018款自动精英型</td>
                            <td>黑/棕</td>
                            <td><span class="VIN">-</span></td>
                        </tr>
                        <tr>
                            <input type="hidden" name="yes" value=""/>
                            <td><input type="checkbox" name="order"  lay-skin="primary" class="layui-input" lay-filter="purchaseCheckbox"/><span class="layui-text-gray" color999>不可选</span></td>
                            <td>大众</td>
                            <td>朗逸</td>
                            <td>2018款自动精英型</td>
                            <td>黑/棕</td>
                            <td><span class="VIN">LS5ADE0AB046793</span></td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </form>
        </div>
        <div class="my_skin">
            <a class="layui-layer-btn1" id="confirm_btn">生成采购单</a>
        </div>
    </div>
</div>
<script src="../../../layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index', //主入口模块
        purchasing: 'purchasing_management/purchasing', //list模块
    }).use(['index','purchasing','jquery','form','table'],function () {
        var $ = layui.$
            ,form = layui.form;
        form.on('checkbox(purchaseCheckboxAll)', function(data){
            console.log(data.elem.checked)
            if(data.elem.checked == true){
                $("input[type='checkbox']").each(function () {
                    $(this).attr("checked",true);
                    $(this).next(".layui-form-checkbox").addClass("layui-form-checked");
                })
            }else{
                $("input[type='checkbox']").each(function () {
                    $("input[type='checkbox']").attr("checked",false);
                    $(this).next(".layui-form-checkbox").removeClass("layui-form-checked");
                })
            }
        });
        form.on('checkbox(purchaseCheckbox)',function (data) {
            console.log(data.elem.checked)
            if(data.elem.checked == true){
                debugger
                data.elem.parentNode.parentNode.children[0].value = 'yes';
            }
        });

        $("#orderTable .VIN").each(function () {
            var td = $(this).parent().parent().find("td:first");
            if($(this).text() == '-'){
                td.find('.layui-input,.layui-form-checkbox').remove();
            }else if($(this).text() != '-'){
                td.find('.layui-text-gray').remove();
            }
        });

        form.render();
    });
</script>
</body>
</html>